package com.bix.util.blizfiles.m2;

import java.nio.ByteBuffer;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.bix.util.blizfiles.BufferUtils;
import com.jme.math.Quaternion;

/**
 * This class represents an animation block of Quaternions. It implements the
 * necessary abstract methods from the animation block class to read in the
 * Quaternions.
 * 
 * @author squid
 * 
 * @version 1.0.0
 */
public class M2QuaternionAnimationBlock extends M2AnimationBlock<Quaternion> {
	private static Log log = LogFactory.getLog (M2QuaternionAnimationBlock.class);

	/**
	 * Instantiate a quaternion animation block from a ByteBuffer.
	 * 
	 * @param bb
	 *          The ByteBuffer to read the data from.
	 */
	public M2QuaternionAnimationBlock(ByteBuffer bb) {
		super (bb);
	}

	/**
	 * This is a method that creates the new key frame data value array. Had to do
	 * this because Java doesn't allow you to use the 'new' operator on a generic
	 * type.
	 * 
	 * @return The newly created array.
	 */
	public Quaternion[][] createKeyFrameDataValueArray () {
		return new Quaternion[this.getKeyFrameData ().length][];
	}

	/**
	 * This method reads a block of data values from a ByteBuffer. The location
	 * and size of the data is passed in the count/offset pair parameter.
	 * 
	 * @param bb
	 *          The ByteBuffer to read the data from.
	 * @param cop
	 *          The count/offset pair of where the data is located in the buffer
	 *          and how long the array is.
	 * 
	 * @return The block of data values read in.
	 */
	public Quaternion[] readKeyFrameDataValues (ByteBuffer bb, M2CountOffsetPair cop) {
		return BufferUtils.getQuaternionArray (bb, cop);
	}

	/**
	 * This method performs a Quaternion interpolation between two other
	 * quaternions.
	 * 
	 * @param q1
	 *          The first quaternion
	 * @param q2
	 *          The second quaternion
	 * @param r
	 *          The interpolation radius.
	 * 
	 * @return The interpolation result of the two quaternions.
	 */
	public Quaternion interpolate (Quaternion q1, Quaternion q2, float r) {
		return new Quaternion (q1, q2, r);
	}
}
